package com.focus.xyz.union.pages.frontend.forms;

import com.focus.xyz.core.common.keyword.Action;
import com.focus.xyz.core.pages.BaseForm;
import com.focus.xyz.core.utils.Constants;
import com.focus.xyz.union.data.ApiBean;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

import java.util.List;

/**
 * Created by chenmeng on 2016/4/20.
 */
public class ApiForm extends BaseForm {
    private Action action;
    @FindBy(id = "api")
    private WebElement form;
    @FindBy(id = "dev_input_btn")
    private WebElement btn;
    @FindBy(id = "dev_modify_btn")
    private WebElement modifyBtn;


    public ApiForm(WebDriver driver, Action action){
        super(driver,action);
        this.action = action;
        PageFactory.initElements(driver,this);
    }
    @Override
    protected List<WebElement> getAllElements() throws Exception {
        List<WebElement> list = form.findElements(By.xpath("div/div/input|div/div/select|div/div/textarea"));
        for(WebElement e:list){
            System.out.println("private String " +e.getAttribute(Constants.ATTR_ID)+";");
        }
        return list;
    }

    public void saveApi(ApiBean apiBean) throws Exception{
        bind(apiBean);
        clickConfirmBtn();
    }

    public void modifyApi(ApiBean bean) throws Exception{
        bind(bean);
        action.click(modifyBtn);
    }

    public void clickConfirmBtn() throws Exception{
        action.click(this.btn);
    }
}
